package modules.pathloss.model;

import datatypes.Antenna;
import datatypes.TerrainType;
import tools.settings.Settings;
import tools.settings.SettingsMissingException;

/**
 *
 * @author Lynne Vandousselaere
 */
public class Calculator {

    private String[] snames = {"urban_correction", "coverage_requirement",
        "building_penetration", "indoor"};

    /**
     *
     * @param a
     * @param settings
     * @return
     */
    public static float getUrbanCorrection(Antenna a, Settings settings) {
        TerrainType terrain = tools.gis.GisTools.getTerrainType(a);
        switch (terrain) {
            case DENSE_URBAN:
                return Float.parseFloat(settings.getParameterValue("urban_correction", "dense_urban"));
            case URBAN:
                return Float.parseFloat(settings.getParameterValue("urban_correction", "urban"));
            case SUBURBAN:
                return Float.parseFloat(settings.getParameterValue("urban_correction", "suburban"));
            case RURAL:
                return Float.parseFloat(settings.getParameterValue("urban_correction", "rural"));
        }
        return 0;
    }
    /**
     *
     * @param a
     * @param settings
     * @param p coverage_requirement
     * @return
     */
    public static double getShadowingMargin(Antenna a, Settings settings, double p)
            throws SettingsMissingException {
        // sigma building instellen
        int indoor = Integer.parseInt(settings.getSettingsValue("indoor"));
        float sigma_building = building_penetration_std_dev_DB;
        if (indoor == 0)
            sigma_building = 0;

        else if (indoor != 1) {
            String[] snames = {"indoor"};
            throw SettingsMissingException.generate("PLMCalculator", "getShadowingMargin", snames);
        }
        p = standardNormInv(p);

        return p*Math.sqrt( Math.pow(sigma_building, 2)+Math.pow(i4 / p,2));

    }
    private static float building_penetration_std_dev_DB = 6f;
    private static float i4 = 10f;

    private static double standardNormInv(double s) {
        // standard norm inverse =STAND.NORM.INV(coverage_requirement)
        return Math.sqrt(Math.pow(s, 2)+Math.pow(s,2));
    }
}
